/**
 * 作者：陈文斌 on 2019/1/9.
 * 邮箱：chen_wennbin@163.com
 * 版本：v1.0
 */

import 'package:flutter/material.dart';
import 'package:crm/constant/constant.dart';
import 'list_tile_normal.dart';

class ListTileText extends StatelessWidget {
  /// 标题
  final Widget title;

  /// 内容
  final String content;

  /// 点击回调
  final GestureTapCallback onTap;

  /// 隐藏分割线
  final bool dividerVisible;

  /// 是否显示必填提示
  final bool requiredVisible;

  /// 隐藏箭头
  final bool arrowVisible;

  ListTileText({
    Key key,
    @required this.title,
    this.onTap,
    this.content = '请选择',
    this.dividerVisible = false,
    this.requiredVisible = true,
    this.arrowVisible = false,
  }) : super(key: key);

  final TextStyle _trailingStyle = TextStyle(
    color: AppColors.PlaceholderTextColor,
    fontSize: AppFontSizes.Font15,
    fontFamily: AppFontFamilies.PingFangSC,
    fontWeight: FontWeight.w500,
  );

  Widget _requiredPrompt() {
    return Offstage(
      offstage: requiredVisible,
      child: Container(
        height: 19,
        padding: EdgeInsets.only(left: 6, top: 4),
        child: Text(
          '*',
          style: TextStyle(
            color: Color(0xFFFF1212),
            fontSize: AppFontSizes.Font15,
          ),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return ListTileNormal(
      key: key,
      title: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          title,
          _requiredPrompt(),
        ],
      ),
      trailing: Text(
        content.length == 0 ? '请选择' : content,
        style: _trailingStyle,
        maxLines: 1,
        overflow: TextOverflow.ellipsis,
      ),
      onTap: onTap,
      dividerVisible: dividerVisible,
      arrowVisible: arrowVisible,
    );
  }
}
